package com.its.us.netty.server.code;

import com.its.us.netty.server.handler.ChatServerHandler;
import com.its.us.netty.server.handler.DataServerHandler;
import com.its.us.netty.server.handler.base.BaseChatServerHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

import java.nio.charset.Charset;

/**
 * @Author: master
 * @Date: 2020/11/1 20:36
 * @Version: 1.0
 */
public class StringDecAndEncInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 向管道加入解码器
        ch.pipeline().addLast("decoder", new StringDecoder(Charset.forName("GBK")));
        // 向管道加入编码器
        ch.pipeline().addLast("encoder", new StringEncoder(Charset.forName("UTF-8")));
        // 加入自己的业务处理
        //ch.pipeline().addLast(new ChatServerHandler());
        ch.pipeline().addLast(new DataServerHandler());
    }
}
